package cc.wsyw126.java.test;

import cc.wsyw126.java.model.User;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by junpeng.yang on 16/11/8.
 */
public class testEmail {
    public static void main(String[] args) {
        String s = "123123";
        String[] split = s.split("\\.");
        System.out.println("split.length = " + split.length);
        for (int i = 0; i < split.length; i++) {
            System.out.println("i = " + i);
        }


        User user1 = new User();
        User user2 = new User();
        User user3 = new User();


        user1.setName("x");
        user1.setPassword("4");
        user2.setName("y");
        user2.setPassword("2");
        user3.setName("y");
        user3.setPassword("3");
        List<User> users = new ArrayList<>();
        users.add(user3);
        users.add(user1);
        users.add(user2);

        System.out.println("--------------");
        Collections.sort(users, (o1, o2) -> o1.getPassword().compareTo(o2.getPassword()) > 0 ? -1 : 1);
        for (User user : users) {
            System.out.println("user = " + user);
        }
        System.out.println("--------------");
//        Collections.sort(users, (o1, o2) -> o1.getName().compareTo(o2.getName()) >0? -1 : 1);
        Collections.sort(users, (o1, o2) -> o1.getName() == o2.getName() ? 0 : o1.getName().equals("y") && o2.getName().equals("x") ? -1 : 1);
        for (User user : users) {
            System.out.println("user = " + user);
        }


        Map<String, List<String>> maps = new HashMap<>();
        List<String> list1 = new ArrayList<>();
        list1.add("AAAA");
        list1.add("AAA");
        list1.add("AA");
        list1.add("A");
        maps.put("a", list1);


        List<String> list2 = new ArrayList<>();
        list2.add("");
        list2.add("BBB");
        list2.add("BB");
        list2.add("B");
        maps.put("b", list2);


        List<String> collect = maps.values().stream().flatMap(strings -> strings.stream()).collect(Collectors.toList());
        System.out.println("collect = " + collect);
    }
}
